
package com.example.helloandroid;

import android.content.Context;
//import android.util.DisplayMetrics;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
//import android.view.animation.Animation;
//import android.view.animation.AnimationUtils;

public class TxalapartaDrawView extends View { 
   private SoundManager mSoundManager;
  // private int zabalera;
    
    public TxalapartaDrawView(Context context) {
        super(context);
        setFocusable(true); //necessary for getting the touch events
        this.setBackgroundResource(R.drawable.mahaia);
//        zabalera = this.getWidth();
//        DisplayMetrics dm = new DisplayMetrics();
//
//        zabalera = (int)dm.widthPixels; 
//        
        // audioarentzat objetua sortu
        mSoundManager = new SoundManager();
        mSoundManager.initSounds(context);
        mSoundManager.addSound(1, R.raw.t1);
        mSoundManager.addSound(2, R.raw.t2);
        mSoundManager.addSound(3, R.raw.t3);
    }
 
    // events when touching the screen
    public boolean onTouchEvent(MotionEvent event) {
        int eventaction = event.getAction(); 
        int X = (int)event.getX(); 
		Log.v("josu", "down "+X);
        switch (eventaction ) { 
		
        case MotionEvent.ACTION_DOWN: // touch down so check if the finger is on a ball
//        	Animation shake = AnimationUtils.loadAnimation(this, R.anim.shake);
//            findViewById(R.id.pw).startAnimation(shake);

//    		if(X<zabalera/3){
//    			mSoundManager.playSound(1);
//			}else if(X<zabalera*0.67){
//				mSoundManager.playSound(2);
//			}else{
//				mSoundManager.playSound(3);
//			}
    		if(X<120){
    			mSoundManager.playSound(1);
			}else if(X<240){
				mSoundManager.playSound(2);
			}else{
				mSoundManager.playSound(3);
			}
            break; 
        } 
        // redraw the canvas
        invalidate(); 
        return true; 
	
    }
}